home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dos6mm.zip / EMSINFO.ASM < prev    next >
Assembly Source File  |  1993-03-31  |  12KB  |  285 lines

  1. ;****************************************************************************
  2. ; EMSINFO displays information about expanded memory, including the EMS
  3. ; version number, the amount of expanded memory installed and available,
  4. ; the number of active handles, and the page frame segment. Its syntax is:
  5. ;
  6. ;       EMSINFO
  7. ;
  8. ; If the EMS version is 4.0 or higher, EMSINFO also reports the number of
  9. ; EMS handles available.
  10. ;****************************************************************************
  11.  
  12. code            segment
  13.                 assume  cs:code,ds:code
  14.                 org     100h
  15. begin:          jmp     main
  16.  
  17. copyright       db      "EMSInfo 1.1 Copyright (c) 1993 Jeff Prosise",13,10
  18.                 db      "From: PC Magazine DOS 6 Memory Management "
  19.                 db      "with Utilities",13,10,13,10,"$"
  20.  
  21. helpmsg         db      "Displays information about expanded memory."
  22. crlf            db      13,10,"$"
  23.  
  24. devname         db      "EMMXXXX0"
  25. errmsg1         db      "No expanded memory manager installed",13,10,"$"
  26. errmsg2         db      "EMS error. Reload the EMS driver and try again."
  27.                 db      13,10,"$"
  28.  
  29. text1           db      "  EMS version  . . . . . . . . . . . . . . . . .  $"
  30. text2           db      "  Available expanded memory pages  . . . . . . . $"
  31. text3           db      "  Unallocated expanded memory pages  . . . . . . $"
  32. text4           db      "  Available expanded memory handles  . . . . . . $"
  33. text5           db      "  Active expanded memory handles . . . . . . . . $"
  34. text6           db      "  Page frame segment . . . . . . . . . . . . . . $"
  35. text7           db      "None$"
  36.  
  37. ems_version             db      ?               ;EMS version number
  38. ems_pages_total         dw      ?               ;Total EMS pages
  39. ems_pages_free          dw      ?               ;Available EMS pages
  40. ems_handles_total       dw      ?               ;Total EMS handles
  41. ems_handles_active      dw      ?               ;Active EMS handles
  42. ems_page_frame          dw      0               ;Page frame segment
  43.  
  44. ;****************************************************************************
  45. ; Procedure MAIN
  46. ;****************************************************************************
  47.  
  48. main            proc    near
  49.                 cld                             ;Clear direction flag
  50.                 mov     si,81h                  ;Point SI to command line
  51.                 call    scanhelp                ;Scan for "/?" switch
  52.                 jnc     main1                   ;Branch if not found
  53.  
  54.                 mov     ah,09h                  ;Display help text and exit
  55.                 mov     dx,offset helpmsg       ;with ERRORLEVEL=0
  56.                 int     21h
  57.                 mov     ax,4C00h
  58.                 int     21h
  59. ;
  60. ; Make sure there is an expanded memory manager installed.
  61. ;
  62. main1:          mov     ah,09h                  ;Display the copyright
  63.                 mov     dx,offset copyright     ;message
  64.                 int     21h
  65.  
  66.                 mov     ax,3567h                ;Check for the signature
  67.                 int     21h                     ;"EMMXXX0" 10 bytes past
  68.                 mov     di,10                   ;the point that the INT
  69.                 mov     si,offset devname       ;67h vector points to
  70.                 mov     cx,8
  71.                 repe    cmpsb
  72.                 je      main2                   ;Branch if driver found
  73.                 mov     dx,offset errmsg1       ;Display error message if
  74.                 jmp     short error_2           ;driver not installed
  75.  
  76. ems_error:      mov     dx,offset errmsg2       ;Display error message
  77. error_2:        mov     ah,09h                  ;and exit with
  78.                 int     21h                     ;ERRORLEVEL=1
  79.                 mov     ax,4C01h
  80.                 int     21h
  81. ;
  82. ; Get the information we need from the driver.
  83. ;
  84. main2:          mov     ax,cs                   ;Make sure the driver and
  85.                 mov     es,ax                   ;hardware are functioning
  86.                 mov     ah,40h
  87.                 int     67h
  88.                 or      ah,ah
  89.                 jnz     ems_error
  90.  
  91.                 mov     ah,46h                  ;Get the EMS version
  92.                 int     67h
  93.                 or      ah,ah
  94.                 jnz     ems_error
  95.                 mov     ems_version,al
  96.  
  97.                 mov     ah,41h                  ;Get the page frame address
  98.                 int     67h
  99.                 or      ah,ah
  100.                 jnz     main3
  101.                 mov     ems_page_frame,bx
  102.  
  103. main3:          mov     ah,42h                  ;Get the number of pages
  104.                 int     67h                     ;present and available
  105.                 or      ah,ah
  106.                 jnz     ems_error
  107.                 mov     ems_pages_total,dx
  108.                 mov     ems_pages_free,bx
  109.  
  110.                 mov     ah,4Bh                  ;Get the number of active
  111.                 int     67h                     ;handles
  112.                 or      ah,ah
  113.                 jnz     ems_error
  114.                 mov     ems_handles_active,bx
  115.  
  116.                 cmp     ems_version,40h         ;If this is EMS 4.0 or
  117.                 jb      main4                   ;higher, get the number
  118.                 mov     ax,5402h                ;of handles supported
  119.                 int     67h
  120.                 or      ah,ah
  121.                 jnz     ems_error
  122.                 mov     ems_handles_total,bx
  123. ;
  124. ; Output the results.
  125. ;
  126. main4:          mov     ah,09h                  ;Display the EMS version
  127.                 mov     dx,offset text1         ;number
  128.                 int     21h
  129.                 mov     ah,02h
  130.                 mov     dl,ems_version
  131.                 mov     cl,4
  132.                 shr     dl,cl
  133.                 add     dl,30h
  134.                 int     21h
  135.                 mov     ah,02h
  136.                 mov     dl,"."
  137.                 int     21h
  138.                 mov     dl,ems_version
  139.                 and     dl,0Fh
  140.                 add     dl,30h
  141.                 int     21h
  142.                 call    newline
  143.  
  144.                 mov     ah,09h                  ;Display total pages
  145.                 mov     dx,offset text2
  146.                 int     21h
  147.                 mov     ax,ems_pages_total
  148.                 call    bin2asc
  149.  
  150.                 mov     ah,09h                  ;Display free pages
  151.                 mov     dx,offset text3
  152.                 int     21h
  153.                 mov     ax,ems_pages_free
  154.                 call    bin2asc
  155.  
  156.                 cmp     ems_version,40h         ;Branch if EMS version is
  157.                 jb      main5                   ;4.0 or less
  158.                 mov     ah,09h                  ;Display total handles
  159.                 mov     dx,offset text4
  160.                 int     21h
  161.                 mov     ax,ems_handles_total
  162.                 call    bin2asc
  163.  
  164. main5:          mov     ah,09h                  ;Display active handles
  165.                 mov     dx,offset text5
  166.                 int     21h
  167.                 mov     ax,ems_handles_active
  168.                 call    bin2asc
  169.  
  170.                 mov     ah,09h                  ;Display page frame segment
  171.                 mov     dx,offset text6
  172.                 int     21h
  173.                 cmp     ems_page_frame,0
  174.                 jne     main6
  175.                 mov     ah,09h
  176.                 mov     dx,offset text7
  177.                 int     21h
  178.                 jmp     short main7
  179. main6:          mov     ax,ems_page_frame
  180.                 call    bin2hex
  181. main7:          call    newline
  182.  
  183.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  184.                 int     21h
  185. main            endp
  186.  
  187. ;****************************************************************************
  188. ; SCANHELP scans the command line for a /? switch. If found, carry returns
  189. ; set and SI contains its offset. If not found, carry returns clear.
  190. ;****************************************************************************
  191.  
  192. scanhelp        proc    near
  193.                 push    si                      ;Save SI
  194. scanloop:       lodsb                           ;Get a character
  195.                 cmp     al,0Dh                  ;Exit if end of line
  196.                 je      scan_exit
  197.                 cmp     al,"?"                  ;Loop if not "?"
  198.                 jne     scanloop
  199.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  200.                 jne     scanloop
  201.  
  202.                 add     sp,2                    ;Clear the stack
  203.                 sub     si,2                    ;Adjust SI
  204.                 stc                             ;Set carry and exit
  205.                 ret
  206.  
  207. scan_exit:      pop     si                      ;Restore SI
  208.                 clc                             ;Clear carry and exit
  209.                 ret
  210. scanhelp        endp
  211.  
  212. ;****************************************************************************
  213. ; BIN2ASC converts a binary value in AX to ASCII form and displays it
  214. ; right-justified.
  215. ;****************************************************************************
  216.  
  217. bin2asc         proc    near
  218.                 mov     bx,10                   ;Initialize divisor word and
  219.                 xor     cx,cx                   ;digit counter
  220. b2a1:           inc     cx                      ;Increment digit count
  221.                 xor     dx,dx                   ;Divide by 10
  222.                 div     bx
  223.                 push    dx                      ;Save remainder on stack
  224.                 or      ax,ax                   ;Loop until quotient is zero
  225.                 jnz     b2a1
  226.  
  227.                 push    cx                      ;Output spaces to right-
  228.                 mov     bx,cx                   ;justify the output
  229.                 mov     cx,4
  230.                 sub     cx,bx
  231.                 jcxz    b2a3
  232. b2a2:           mov     ah,02h
  233.                 mov     dl,20h
  234.                 int     21h
  235.                 loop    b2a2
  236. b2a3:           pop     cx
  237.  
  238. b2a4:           pop     dx                      ;Retrieve a digit from stack
  239.                 add     dl,30h                  ;Convert it to ASCII
  240.                 mov     ah,2                    ;Display it
  241.                 int     21h
  242.                 loop    b2a4                    ;Loop until done
  243.                 call    newline                 ;Move cursor to next line
  244.                 ret
  245. bin2asc         endp
  246.  
  247. ;****************************************************************************
  248. ; BIN2HEX displays the 4-digit hex number in AX.
  249. ;****************************************************************************
  250.  
  251. bin2hex         proc    near
  252.                 mov     cx,4
  253. b2h1:           push    cx
  254.                 mov     cx,4
  255.                 xor     dl,dl
  256. b2h2:           shl     ax,1
  257.                 rcl     dl,1
  258.                 loop    b2h2
  259.                 add     dl,30h
  260.                 cmp     dl,39h
  261.                 jbe     b2h3
  262.                 add     dl,7
  263. b2h3:           push    ax
  264.                 mov     ah,02h
  265.                 int     21h
  266.                 pop     ax
  267.                 pop     cx
  268.                 loop    b2h1
  269.                 ret
  270. bin2hex         endp
  271.  
  272. ;****************************************************************************
  273. ; NEWLINE moves the cursor to the next line.
  274. ;****************************************************************************
  275.  
  276. newline proc    near
  277.                 mov     ah,09h
  278.                 mov     dx,offset crlf
  279.                 int     21h
  280.                 ret
  281. newline         endp
  282.  
  283. code            ends
  284.                 end     begin
  285.